public class Work06 {
    private static int[] nums = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12};
    private static boolean[] isUsed = new boolean[20];
    private static int[] res = new int[20];
    private static int count = 0;

    private static int dfs(int start, int end) {
        if (start == end) {

            int sum = res[1] + res[3] + res[6] + res[9];
            if (res[1] + res[4] + res[8] + res[10] == sum && res[2] + res[3] + res[4] + res[5] == sum &&
                    res[2] + res[6] + res[7] + res[10] == sum && res[5] + res[7] + res[8] + res[9] == sum) {
                count++;
            }

        }
        for (int i = 0; i < end; i++) {
            if (isUsed[i] == false) {
                res[start] = nums[i];
                isUsed[i] = true;
                dfs(start + 1, end);
                isUsed[i] = false;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int dfs = dfs(1, 10);
        System.out.println(dfs/10);
    }

}
